using GamFi.API.Application.Contracts.Wallet.GetWalletInfo;
using GamFi.API.Application.Contracts.Wallet.PostChangeBalance;
using GamFi.API.Application.Features.Queries.Wallet.GetWalletInfo;
using GamFi.API.Application.Features.Queries.Wallet.PostChangeBalance;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace GamFi.API.WEB.Controllers;

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class WalletController(IMediator mediator) : Controller
{
    /// <summary>
    /// Возвращает баланс и транзакции
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns>баланс и транзакции</returns>
    [HttpGet("GetWalletInfo")]
    public async Task<GetWalletInfoResponse> GetWalletInfo(CancellationToken cancellationToken)
        => await mediator.Send(new GetWalletInfoQuery(), cancellationToken);

    /// <summary>
    /// Пополнение или снятие
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    [HttpPatch("ChangeBalance")]
    public async Task PostChangeBalance([FromBody] PatchChangeBalanceRequest request, CancellationToken cancellationToken)
        => await mediator.Send(new PostChangeBalanceCommand(request), cancellationToken);
}